#pragma once
#ifndef ItemBrowser_h__
#define ItemBrowser_h__

#include <QString>
#include <memory>

#include "Task.h"

class Item;
class ItemBrowserConfig;
class TaskManager;
class ItemBrowser : public Task
{
    Q_OBJECT
public:
    ItemBrowser(TaskManager *manager);
    ~ItemBrowser();
public:
    // methods : 
    virtual void start() override;
    void waitForFinished() const;
public:
    // extra tasks:
    void goCollectShop();
    void updateSubitemsLink();
    void updateShopIndexLink();
public:
    // setter :
    void setItem(const Item &item);
    void setConfigure(const ItemBrowserConfig &configure);
    void setSupportKeyword(const QString &supportKeyword);
signals:
    void subItemsLinkUpdated(const QString &link);
    void shopIndexLinkUpdated(const QString &link);
    // internal processes
private:
    void itemTabLoaded(QVariantMap arg);
    void topArrived(QVariantMap arg);
    void midArrived(QVariantMap arg);
    void bottomArrived(QVariantMap arg);
    void ratesArrived(QVariantMap arg);
    void tradesArrived(QVariantMap arg);
    void collectItemArrived(QVariantMap arg);
    void collectShopArrived(QVariantMap arg);
    void on_subItemsLinkUpdated(QVariantMap arg);
    void on_shopIndexLinkUpdated(QVariantMap arg);
private:
    TaskManager *manager = nullptr;
    std::unique_ptr<const Item> currentItem;
    std::unique_ptr<const ItemBrowserConfig> config;
    QString supportKeyword;
    volatile bool _finished = false;
};

#endif // ItemBrowser_h__